package com.geo.geotool.service.trans;


import com.geo.geotool.entity.enmu.GeoFormatEnum;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * • @Description: 地理坐标识别
 * • @author  : yell
 * • @date : 2021/12/10  18:21
 */
public class GeometryFormatCapture {
    public static String capture(String geoString) throws Exception{
        GeoFormatEnum thisFormat = null;
        for(GeoFormatEnum geoFormatEnum : GeoFormatEnum.values()){
            /**正则匹配 大小写不敏感,多行**/
            Pattern pattern = Pattern.compile(geoFormatEnum.getPattern(),Pattern.CASE_INSENSITIVE|Pattern.DOTALL);
            Matcher matcher = pattern.matcher(geoString);
            if(matcher.matches()){
                thisFormat = geoFormatEnum;
                break;
            }
        }
        if(thisFormat==null){
            throw new Exception("GeoFormat:找不到该格式;GeoContent:"+geoString);
        }
        return thisFormat.getType();
    }
}
